﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.malls.ui {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.geom.*;
    import Mechanics.GameMechanicInterfaces.*;
    import Mechanics.*;
    import Events.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.sim.*;
    import org.aswing.geom.*;
    import Display.*;
    import Display.MarketUI.*;
    import org.aswing.event.*;
    import Mechanics.GameEventMechanics.*;
    import Display.GridlistUI.*;
    import Modules.malls.MarketUI.view.*;
    import Modules.malls.MarketUI.model.*;

    public class MallCatalogUI extends MechanicTabbedCatalogUI {

        public static const NUM_SLOTS_PER_FLOOR:int = 4;

        public function MallCatalogUI(_arg1:IMechanicUser){
            super(_arg1);
            this.overrideTitle = "Mall_title";
            Global.ui.addEventListener(GenericObjectEvent.OBJECT_STORED, this.onObjectStored, false, 0, true);
            Global.ui.addEventListener(GenericObjectEvent.OBJECT_PLACED_FROM_STORAGE, this.onPlacedFromStorage, false, 0, true);
            Global.ui.addEventListener(GenericObjectEvent.CREW_PURCHASE, this.onRefresh, false, 0, true);
            Global.ui.addEventListener(GenericObjectEvent.BUILDING_UPGRADE, this.onRefreshTabs, false, 0, true);
            Global.ui.addEventListener(GenericObjectEvent.STORED_ITEM_UPGRADE, this.onStoredItemUpgrade, false, 0, true);
            Global.ui.addEventListener(GenericObjectEvent.STORED_ITEM_SUPPLY, this.onStoredItemSupply, false, 0, true);
        }
        override protected function getTabBackground(_arg1:String):DisplayObject{
            if (!this.isTabLocked(_arg1)){
                return (super.getTabBackground(_arg1));
            };
            return (new (TabbedCatalog.assetDict["tab_locked"])());
        }
        protected function isTabLocked(_arg1:String):Boolean{
            var _local2:Item = (m_generator as ItemInstance).getItem();
            var _local3:int = UpgradeDefinition.getFullUpgradeChainNames(Item.findUpgradeRoot(_local2)).indexOf(_local2.name);
            var _local4 = (_local3 >= getIndexFromTabId(_arg1));
            return (!(_local4));
        }
        override protected function loadItemsForTab(_arg1:int):Array{
            var _local18:Component;
            var _local19:Component;
            var _local2:Array = new Array();
            var _local3:int = this.getNumSlotsPerFloor();
            var _local4:IStorage = (MechanicManager.getInstance().getMechanicInstance(m_generator, "slots", "GMMechanicStore") as IStorage);
            var _local5:MallHarvestMechanic = (MechanicManager.getInstance().getMechanicInstance(m_generator, "harvestState", "GMPlay") as MallHarvestMechanic);
            var _local6:Array = m_generator.getDataForMechanic("slots");
            var _local7:Array = new Array();
            var _local8:int = (_arg1 * _local3);
            while (_local8 < ((_arg1 + 1) * _local3)) {
                if (_local8 >= _local6.length){
                    break;
                };
                _local7.push(_local6[_local8]);
                _local8++;
            };
            var _local9:int = (m_generator as MechanicMapResource).getItem().storageInitCapacity;
            var _local10:int = _local4.getStorageCapacity();
            var _local11:int = (_local10 - (_arg1 * _local3));
            var _local12:int;
            while (_local12 < _local3) {
                if ((((_local12 < _local7.length)) && ((_local12 < _local11)))){
                    _local18 = new MallBusinessCellView(m_generator, _local12, _arg1, _local7[_local12]);
                    _local2.push(new GenericGridListData(_local7[_local12], _local18));
                } else {
                    if (_local12 < _local11){
                        _local19 = new MallBusinessCellView(m_generator, _local12, _arg1);
                        _local2.push(new GenericGridListData(null, _local19));
                    } else {
                        _local2.push(new GenericGridListData(null, new MallCrewableCellView(m_generator, _local12)));
                    };
                };
                _local12++;
            };
            var _local13:ItemInstance;
            var _local14:Mall = (m_generator as Mall);
            var _local15:String = _local14.getMysteryBusinessItemName(_arg1);
            if (_local14.hasMysteryBusinessInInventory(_arg1)){
                _local13 = new ItemInstance(_local15);
            };
            var _local16:int = this.getNumSlotsPerFloor();
            var _local17:MallMysteryCellView = new MallMysteryCellView(m_generator, _local16, _arg1);
            _local2.push(new GenericGridListData(_local13, _local17));
            return (_local2);
        }
        override protected function changeCategoryFromTab(_arg1:MouseEvent):void{
            var _local3:UpgradeMechanic;
            var _local2:String = _arg1.currentTarget.name;
            if (!this.isTabLocked(_local2)){
                super.changeCategoryFromTab(_arg1);
            } else {
                _local3 = (MechanicManager.getInstance().getMechanicInstance(m_generator, "upgrade", "GMPlay") as UpgradeMechanic);
                if (_local3){
                    _local3.doDisplayGate();
                };
            };
        }
        override protected function showToolTip(_arg1:MouseEvent):void{
            var _local2:String = m_tabsDict[(_arg1.currentTarget as JPanel)];
            var _local3:int = getIndexFromTabId(_local2);
            var _local4:JPanel = (_arg1.currentTarget as JPanel);
            var _local5:IntPoint = _local4.getGlobalLocation();
            var _local6:Point = new Point(_local5.x, _local5.y);
            var _local7:Object = new Object();
            _local7["type"] = TooltipType.DESCRIPTION;
            var _local8:Number = _local3;
            _local7["title"] = ZLoc.t("Dialogs", (("MallCatalogUI" + _local8) + "_tab"));
            var _local9:int;
            if ((m_generator is Mall)){
                _local9 = (m_generator as Mall).getInitialHarvestBonusForFloor(_local3);
            };
            _local7["description"] = ZLoc.t("Dialogs", "MallTabText", {bonus:_local9});
            if (_local3 > 0){
                _local7["requirement"] = ZLoc.t("Dialogs", "MallTabReq", {floorNum:_local3});
            };
            var _local10:Point = new Point(47, -55);
            var _local11:DataItemEvent = new DataItemEvent(DataItemEvent.SHOW_TOOLTIP, null, _local6, true);
            _local11.setParams(_local7);
            _local11.setOffset(_local10);
            dispatchEvent(_local11);
        }
        override protected function hideToolTip(_arg1:MouseEvent):void{
            dispatchEvent(new Event("turnOffToolTip", true));
        }
        protected function getNumSlotsPerFloor():int{
            return (NUM_SLOTS_PER_FLOOR);
        }
        override public function getTabbedCatalogKey():String{
            return ("MallCatalogUI");
        }
        override protected function makeShelf(_arg1:Array):MarketScrollingList{
            var _local2:MallScrollingList = new MallScrollingList(_arg1, MallCellModel, 0, 7, 1);
            return (_local2);
        }
        override public function goToItem(_arg1:String):void{
        }
        override public function getLocalizedTabName(_arg1:int):String{
            var _local2:Number = _arg1;
            return (ZLoc.t("Dialogs", ((this.getTabbedCatalogKey() + _local2) + "_tab")));
        }
        private function onObjectStored(_arg1:GenericObjectEvent):void{
            refreshShelf();
        }
        private function onPlacedFromStorage(_arg1:GenericObjectEvent):void{
            refreshShelf();
        }
        private function onRefresh(_arg1:GenericObjectEvent):void{
            refreshShelf();
        }
        private function onStoredItemUpgrade(_arg1:GenericObjectEvent):void{
            refreshShelf();
        }
        private function onStoredItemSupply(_arg1:GenericObjectEvent):void{
            refreshShelf();
        }
        private function onRefreshTabs(_arg1:GenericObjectEvent):void{
            refreshTabs();
        }
        override protected function closeCatalog(_arg1:AWEvent):void{
            super.closeCatalog(_arg1);
            UI.clearTabbedCatalog();
            Global.world.setDefaultGameMode();
        }
        override protected function trackPageView(_arg1:String, _arg2:int):void{
            StatsManager.sample(100, "market_views", "MallCatalogUI", ("tab" + getCurrentTabIndex()));
        }

    }
}//package Modules.malls.ui 
